package cn.xd.itstack.springframework.beans.bean;

import cn.xd.itstack.springframework.beans.BeansException;
import cn.xd.itstack.springframework.beans.factory.*;
import cn.xd.itstack.springframework.context.ApplicationContext;
import cn.xd.itstack.springframework.context.ApplicationContextAware;

/**
 * @Classname UserApplyPropertyValues
 * @Description TODO
 * @Date 2022/5/12 下午5:59
 * @Created by lvxiaodong
 */
public class UserApplyPropertyValues implements InitializingBean, DisposableBean, BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, ApplicationContextAware {

    private int userId;

    private String company;

    private String location;

    private UserDao userDao;

    private ApplicationContext applicationContext;

    private BeanFactory beanFactory;

    private ClassLoader classLoader;


    public void setUserId(int userId) {
        this.userId = userId;
    }

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String queryUserInfo(){
        String result =userDao.getUserId(userId)+"company:"+company+"location:"+location;
        System.out.println(result);
        return result;
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("执行：UserService.destroy");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("执行：UserService.afterPropertiesSet");
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
      System.out.println("classLoad:"+classLoader);
      this.classLoader = classLoader;

    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("beanFactory:"+beanFactory);
        this.beanFactory = beanFactory;
    }

    @Override
    public void setBeanName(String beanName) {
        System.out.println("beanName:"+beanName);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("applicationContext:"+applicationContext);
        this.applicationContext =applicationContext;
    }

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public BeanFactory getBeanFactory() {
        return beanFactory;
    }

    public ClassLoader getClassLoader() {
        return classLoader;
    }
}
